import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  page = "/auth-service/oauth2/client/page",
  get = "/auth-service/oauth2/client/get",
  list = "/auth-service/oauth2/client/list",
  listExtLdpConn = "/auth-service/oauth2/client/listExtLdpConn",
  save = "/auth-service/oauth2/client/save",
  edit = "/auth-service/oauth2/client/updateById",
  delete = "/auth-service/oauth2/client/deleteById",
  deleteBatch = "/auth-service/oauth2/client/deleteBatch",
  refreshCache = "/auth-service/oauth2/client/refreshCache",
}

export const pageClient = (params) => {
  return defHttp.get({url: Api.page, params});
}

export const getClient = (params) => {
  return defHttp.get({url: Api.page, params});
}

export const listClient = (params) => {
  return defHttp.get({url: Api.list, params});
}

export const listExtLdpConn = (params) => {
  return defHttp.get({url: Api.listExtLdpConn, params});
}

export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

export const refreshCache = () => {
  return defHttp.get({url: Api.refreshCache});
}

export const deleteOauthClient = (params, handleSuccess) => {
  return defHttp.delete({url: Api.delete, data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeleteOauthClient = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}